﻿using Centny.PdfReader.Types;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Centny.PdfReader.Pdf
{
    public class PdfStreamObject : PdfClassObject
    {
        public PdfStreamObject()
        {
            this.Stream = null;
        }
        //public PdfDictionary Elements { get; set; }
        public PdfStream Stream { get; set; }
        public long Length
        {
            get
            {
                PdfClass t = this[StreamKeys.Length];
                if (t is PdfLong)
                {
                    return (t as PdfLong).AsLong;
                }
                else if (t is PdfReference)
                {
                    PdfClassObject pco = this.Doc.RealObject(t as PdfReference) as PdfClassObject;
                    return (pco.InnerObj as PdfLong).AsLong;
                }
                else
                {
                    throw new InvalidDataException("not length found");
                }
            }
        }
        public Stream RStream()
        {
            return this.Doc.ReadStream(this, true);
        }
        public Stream RStream(bool deflated)
        {
            return this.Doc.ReadStream(this, deflated);
        }
    }
}
